package tools.Derby;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *
 * @author 郝国生
 * 功能：负责完成连接数据库及关闭数据库
 * 要求：凡是继承该类的都要写构造函数，并在构造函数的第1句写上super()
 */
public class DerbyManager {

    public DerbyConnection derby1 = new DerbyConnection();
    public Connection con;
    public Statement stmt;

    public DerbyManager() throws SQLException {
        derby1.setDbName("Dictionary");
        derby1.setPassword("htt");
        derby1.setName("htt");
        derby1.setUrl("jdbc:derby:Dictionary;create=false;user=htt;password=htt");
        derby1.setJdbcType("org.apache.derby.jdbc.EmbeddedDriver");
        con=derby1.getConnection();
        stmt=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
    }

    protected void destroy() throws SQLException {
        stmt.close();
        stmt = null;
        derby1.closeConnection(con);
        con = null;
    }
}
